package com.golddaymicromall.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.golddaymicromall.activity.R;
import com.golddaymicromall.bean.NoticeInfo;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by dawd on 2016/3/2.
 */
public class NoticeAdapter extends BaseAdapter {
    private List<NoticeInfo> list;
    private Context ctx;
    public NoticeAdapter(List<NoticeInfo>list,Context ctx){
        this.list = list;
        this.ctx = ctx;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder hold;
        if(convertView == null){
            convertView = View.inflate(ctx, R.layout.item_notice, null);
            hold = new ViewHolder();
            hold.notice_Date = (TextView) convertView.findViewById(R.id.notice_Date);
            hold.notice_title = (TextView) convertView.findViewById(R.id.notice_title);
            convertView.setTag(hold);
        }else{
            hold = (ViewHolder) convertView.getTag();
        }
        hold.notice_title.setText(list.get(position).getTitle());
        String getMessagedate=dateToString(list.get(position).getBegindate());
        hold.notice_Date.setText(getMessagedate.toString());
        return convertView;
    }
    public String dateToString(Date ctime){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");;
        return formatter.format(ctime);
    }
    private class ViewHolder{
        TextView notice_Date;
        TextView notice_title;
    }
}
